/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bankingsystem;

import java.util.Scanner;

/**
 * The Main class that contains the static main() method which is invoked
 * first at runtime.
 * @author Gokul
 * @version 1.0
 */
public class BankInterface {

    /**
     * The main method that is called first then the program is run.
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        new BankInterface().init();
    }

    /**
     * This method is used to obtain the user's choice as to
     * which feature of the banking system he/she wants to access.
     */
    public void init(){

        PersistenceManager pm = new PersistenceManager();
        Bank b = pm.readData();

        if(b == null){
            System.out.println("Loading from Default ");
            b= new Bank(); /*creating a new instance if reading fails.*/
        }
        /*prompt*/

        System.out.println("~~~~~~~~~~ CodeX Banking System ~~~~~~~~~~");
        System.out.println("\nWELCOME TO CODEX INC. BANKING SYSTEM.");
        System.out.println("Choose an option below to continue:");
        System.out.println("1 - Staff interface");
        System.out.println("2 - Customer interface");
        System.out.println("3 - Internet banking");
        System.out.println("4 - ATM");
        System.out.println("0 - Exit");
        System.out.print("\n>>");
        Scanner sc = new Scanner(System.in);

        int choice = 0;
            try{
                choice = sc.nextInt();    /*capturing the user's next keystroke.*/
            }
            catch(Exception e){
                System.out.println("Enter an integer only.");
            }


            switch (choice) {
                case 1:
                    /*creating a new StaffFrontEnd instance and passing it the bank object
                    read from the file and this BankInterface object.*/
                    StaffFrontEnd s = new StaffFrontEnd(b,this);
                    break;
                case 2:
                    /*creating a new CustomerFrontEnd instance and passing it the bank object
                    read from the file.*/
                    CustomerFrontEnd cf = new CustomerFrontEnd(b,this);
                    break;
                case 3:
                    /*creating a new OnlineBanking instance and passing it the bank object
                    read from the file.*/
                    OnlineBanking ol = new OnlineBanking(b,this);
                    break;
                    case 4:
                    /*creating a new ATM instance and passing it the bank object
                    read from the file.*/
                    ATM a = new ATM(b);
                    break;
                case 0:
                    /*code for exit*/
                    System.out.println("Thank you for using the system.");
                    System.exit(0);
                    break;
                default:
                    /*invalid choice entered*/
                    System.out.println("Your choice is not valid. Please choose again.");
                    break;
            }
        
    }

}
